﻿namespace Beehive_Management_System
{
    class Queen : Bee
    {
        private Worker[] workers;

        public Queen(Worker[] workers) : base(275)
        {
            this.workers = workers;
        }

        private int shiftNumber = 0;

        public bool AssignWork(string job, int numberOfShift)
        {
            for (int i = 0; i < workers.Length; i++)
            {
                if (workers[i].DoThisJob(job, numberOfShift))
                {
                    return true;
                }
            }

            return false;
        }

        public override double GetHoneyConsumption()
        {
            double consumption = 0;
            double largestWorkerConsuprion = 0;
            int workersDoingJob = 0;

            for (int i = 0; i < workers.Length; i++)
            {
                if (workers[i].GetHoneyConsumption() > largestWorkerConsuprion)
                {
                    largestWorkerConsuprion = workers[i].GetHoneyConsumption();
                }
                if (workers[i].ShiftsLeft > 0)
                {
                    workersDoingJob++;
                }
            }

            consumption += largestWorkerConsuprion;

            if (workersDoingJob >= 3)
            {
                consumption += 30;
            }
            else
            {
                consumption += 20;
            }

            return consumption;
        }

        public string WorkTheNextShifts()
        {
            double totalConsumption = 0;

            for (int i = 0; i < workers.Length; i++)
            {
                totalConsumption += workers[i].GetHoneyConsumption();
            }

            //totalConsumption += GetHoneyConsumption();

            shiftNumber++;
            string report = "Отчет для смены#" + shiftNumber + "\r\n";

            for (int i = 0; i < workers.Length; i++)
            {
                if (workers[i].WorkOneShift())
                {
                    report += "Рабочий#" + (i + 1) + " закончил работу\r\n";
                }
                if (string.IsNullOrEmpty(workers[i].CurrentJob))
                {
                    report += "Рабочий#" + (i + 1) + " не работает\r\n";
                }
                else
                {
                    if (workers[i].ShiftsLeft > 0)
                    {
                        report += "Рабочий#" + (i + 1) + " выполняет '" + workers[i].CurrentJob + "' еще "
                                + workers[i].ShiftsLeft + " смен\r\n";
                    }
                    else
                    {
                        report += "Рабочий#" + (i + 1) + " закончит '" + workers[i].CurrentJob + "' после этой смены\r\n";
                    }
                }
            }

            report += "Общее потребление меда: " + totalConsumption + " единиц";

            return report;
        }
    }
}
